package com.ruoyi.code.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.code.domain.RedeemCode;
import com.ruoyi.code.service.IRedeemCodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 兑换码管理Controller
 * 
 * @author ximu
 * @date 2023-03-17
 */
@RestController
@RequestMapping("/code/codemanage")
public class RedeemCodeController extends BaseController
{
    @Autowired
    private IRedeemCodeService redeemCodeService;

    /**
     * 查询兑换码管理列表
     */
    @PreAuthorize("@ss.hasPermi('code:codemanage:list')")
    @GetMapping("/list")
    public TableDataInfo list(RedeemCode redeemCode)
    {
        startPage();
        List<RedeemCode> list = redeemCodeService.selectRedeemCodeList(redeemCode);
        return getDataTable(list);
    }

    /**
     * 导出兑换码管理列表
     */
    @PreAuthorize("@ss.hasPermi('code:codemanage:export')")
    @Log(title = "兑换码管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RedeemCode redeemCode)
    {
        List<RedeemCode> list = redeemCodeService.selectRedeemCodeList(redeemCode);
        ExcelUtil<RedeemCode> util = new ExcelUtil<RedeemCode>(RedeemCode.class);
        util.exportExcel(response, list, "兑换码管理数据");
    }

    /**
     * 获取兑换码管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('code:codemanage:query')")
    @GetMapping(value = "/{redeemCodeId}")
    public AjaxResult getInfo(@PathVariable("redeemCodeId") Long redeemCodeId)
    {
        return success(redeemCodeService.selectRedeemCodeByRedeemCodeId(redeemCodeId));
    }

    /**
     * 新增兑换码管理
     */
    @PreAuthorize("@ss.hasPermi('code:codemanage:add')")
    @Log(title = "兑换码管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RedeemCode redeemCode)
    {
        return toAjax(redeemCodeService.insertRedeemCode(redeemCode));
    }

    /**
     * 修改兑换码管理
     */
    @PreAuthorize("@ss.hasPermi('code:codemanage:edit')")
    @Log(title = "兑换码管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RedeemCode redeemCode)
    {
        return toAjax(redeemCodeService.updateRedeemCode(redeemCode));
    }

    /**
     * 删除兑换码管理
     */
    @PreAuthorize("@ss.hasPermi('code:codemanage:remove')")
    @Log(title = "兑换码管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{redeemCodeIds}")
    public AjaxResult remove(@PathVariable Long[] redeemCodeIds)
    {
        return toAjax(redeemCodeService.deleteRedeemCodeByRedeemCodeIds(redeemCodeIds));
    }
}
